<extend name="Public/base"/>
<block name="body">
  <div class="main-title">
    <h2>分类管理</h2>
  </div>
  <!-- /表格列表 --> 
  <!--添加商品选择分类-->
  <div class="item-field">
    <h4 class="title"><i>1</i>选择分类商品</h4>
    <div class="form-item cf cc-tree-mian form-horizontal">
      <div class="form-item cf cc-tree-box J_class">
        <ul class="cc-tree-cont" data-deep="2">
        <volist name="list" id="vo">
          <li data-id="{$vo.id}">{$vo.name}</li>
        </volist>
        </ul>
        <ul class="cc-tree-cont" data-deep="3"></ul>
        <ul class="cc-tree-cont" data-deep="4"></ul>
      </div>
      <div class="form-item J_class_show"></div>
      <div class="form-item form-action cf">
        <button class="btn J_submit" id="submit" disabled="disabled" >下一步 填写商品信息</button>
      </div>
    </div>
  </div>
</block>
<block name="script"> 
  <script type="text/javascript">
    (function($){
      /* 分类展开收起 */
      $('.J_class').on('click','ul li',function(){
          $(this).addClass('in').siblings().removeClass('in');
          var id = $(this).attr('data-id');
          var deep = $(this).parent('ul').attr('data-deep');
          var _this = $(this);
          if(id == '' || deep == '4'){
              return false;
          }
          var class_text = '';
          
          $.post("{:U('ajaxClass')}",{id:id},function(rst){
              if(rst.status != 0){
                  _this.parent('ul').next().html(rst.html);
                  /* 分类展示 */
                  $('.J_class ul').each(function(index,obj){
                      if($(obj).find('li').hasClass('in')){
                          if(index == '0'){
                              class_text = $(obj).find('li.in').text();
                          }else{
                              class_text += ' > '+$(obj).find('li.in').text();
                          }
                      }
                  });
                  $('.J_class_show').html('您选择的分类是：'+class_text);
                  if(rst.html == ''){
                      $('.J_submit').removeAttr('disabled');
                  }else{
                      $('.J_submit').attr("disabled","disabled");
                  }
                  
              }else{
                  alert(rst.info);
              }
          },'json');
          
      });
      
      /* 填写商品信息 */
      $('.J_submit').on('click',function(){
    	  var url = "{:U('Item/add')}";
    	  $('.J_class ul').each(function(index,obj){
              if($(obj).find('li').hasClass('in')){
                  if(index == '0'){
                	  url += '?cid_1='+$(obj).find('li.in').attr('data-id');
                  }else{
                      url += '&cid_'+(index+1)+'='+$(obj).find('li.in').attr('data-id');
                  }
              }
          });
    	  window.location.href=url;
    	  return false;
      });
    })(jQuery);
  </script> 
</block>
